// 1.导入http模块
const http = require('http');
const url = require('url')
 
//2.创建web服务器实例
const server = http.createServer();
//3.为服务器绑定 request事件  监听客户请求
server.on('request', function(req, res) {
    if(req.method === 'Get') {
        res.end('GET')
    }
    if(req.method === 'POST') {
        let data = ''
        req.on('data', (params) => {
            data += params;
        })
        req.on('end', () => {
        res.setHeader('Content-Type', 'application/json')
        res.statusCode = 200 
    
        res.end('{name:12}')
        })
    }
});
//4.启动服务器
server.listen(8081, function() {
    console.log('server running at http://localhost/:8081');
})
